<?php
class Qr extends MY_Controller
{
    public function index()
    {
    	$id = intval($this->input->get_post('id'));
    	$type = $this->input->get_post('type');
    	
    	switch ($type) {
    		case 'staff_invite':
    			$url = url('m').'user/agent_invite?sid='.$id;
    			break;
    		case 'agent_invite':
    			$url = url('m').'user/agent_invite?uid='.$id;
    			break;
    	}
    	
    	if($url)
    	{
    		$path      = 'qr'.DS.$type.DS.($id%10).DS;
    		$filename  = $id.'.jpg';
    		$invite_qr = url('static').$path.$filename;
    		 
    		if (!file_exists(STATICPATH.$path.$filename))
    		{
    			@mkdir(STATICPATH.$path, 0777, true);
    			
    			$this->load->library('qr/qr_code_lib');
    			$this->qr_code_lib->jpg($url, STATICPATH.$path.$filename);
    		}
    		
    		header('Location: '.$invite_qr);
    	}
    }
}